Skip to content

src: simplify memory management using node::Malloc() and friends#8482

Merged
addaleax merged 4 commits intonodejs:masterfrom
addaleax:allocation-rework
Sep 29, 2016
Merged

src: simplify memory management using node::Malloc() and friends#8482
addaleax merged 4 commits intonodejs:masterfrom
addaleax:allocation-rework

Conversation

@addaleax
Copy link
Member

@addaleax addaleax commented Sep 10, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

src

Description of change
  • Add an optional size param to node::Malloc() and node::Realloc() in calloc(3)-style and use proper overflow detection.
  • Make the allocation methods templates so that they directly give the correct return type, removing a number of static_casts to the desired pointer types.
  • Add shortcuts for the node::Malloc() + CHECK_NE(·, nullptr) combinations that often occur together in the codebase.
  • Call v8::Isolate::GetCurrent()->LowMemoryNotification() when an allocation fails to give V8 a chance to clean up and return memory before retrying (and possibly giving up).

Any of the changes here can be left out but I believe that they all pretty much make sense to have.

CI: https://ci.nodejs.org/job/node-test-commit/4994/
CI: https://ci.nodejs.org/job/node-test-commit/4995/
CI: https://ci.nodejs.org/job/node-test-commit/4996/
CI: https://ci.nodejs.org/job/node-test-commit/4997/
CI: https://ci.nodejs.org/job/node-test-commit/5008/
CI: https://ci.nodejs.org/job/node-test-commit/5013/
CI: https://ci.nodejs.org/job/node-test-commit/5025/

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants